package servlet;

import service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AdminUserDeleteServlet", urlPatterns = "/admin/user_delete")
public class AdminUserDeleteServlet extends HttpServlet {

    UserService userService = new UserService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        int id = Integer.parseInt(request.getParameter("id"));

        boolean issuccess = userService.delete(id);
        if (issuccess) {

            request.setAttribute("msg","用户删除成功!");
        }else {
            request.setAttribute("failMsg","客户有订单存在，请删除订单，再来删除用户信息!");
        }

        request.getRequestDispatcher("/admin/user_list").forward(request,response);
    }
}
